/**
 * 
 */
package facade;

import java.util.ArrayList;
import java.util.Date;

import factory.*;
import metier.*;
import metier.JDBC.AnneeEtudeJDBC;

/**
 * @author 
 *
 */
public class FacadeAnneeEtude {
	private Factory factory = new FactoryJDBC();
	private Formation formation=null;
	private AnneeEtude annee=null;
	private Formation formationAnnee = null;
	private Semestre semestre = null;
	private Matiere matiere = null;
	private Semestre semestre1=null;
	private Semestre semestre2=null;
	private Conge conge=null;
	
	/**
	 * @return the conge
	 */
	public Conge getConge() {
		return conge;
	}

	/**
	 * @param conge the conge to set
	 */
	public void setConge(Conge conge) {
		this.conge = conge;
	}

	/**
	 * @return the semestre1
	 */
	public Semestre getSemestre1() {
		return semestre1;
	}

	/**
	 * @param semestre1 the semestre1 to set
	 */
	public void setSemestre1(Semestre semestre1) {
		this.semestre1 = semestre1;
	}

	/**
	 * @return the semestre2
	 */
	public Semestre getSemestre2() {
		return semestre2;
	}

	/**
	 * @param semestre2 the semestre2 to set
	 */
	public void setSemestre2(Semestre semestre2) {
		this.semestre2 = semestre2;
	}

	/**
	 * @return the annee
	 */
	public AnneeEtude getAnnee() {
		return annee;
	}

	/**
	 * @param annee the annee to set
	 */
	public void setAnnee(AnneeEtude annee) {
		this.annee = annee;
	}

	public void creerAnneeEtude (int id) throws ExceptionMetier{
		annee=factory.creerAnneeEtude();
		annee.load(id);
	}
	
	public void creerAnneeEtude () {
		annee=factory.creerAnneeEtude();
	}
	public FacadeAnneeEtude() {
		super();
		this.factory = new FactoryJDBC();
	}

	/**
	 * @return
	 */
	public ArrayList<ElementListe> creerListeFormation(){
		return factory.creerListeFormation();
	}
	public void creerFormation(String nom, String description) {
		formation= factory.creerFormation(nom, description); 
		
	}public void creerFormationAnnee() {
		formationAnnee= factory.creerFormation(); 
	}
	
	
	/**
	 * @return
	 */
	/*public ArrayList<ElementListe> creerListeSemestre(){
		return factory.creerListeSemestre();
	}*/
	public void creerSemestre(String nom, AnneeEtude annee, Date debut, Date fin) {
			semestre = factory.creerSemestre(nom, annee, debut, fin); 
		}
	/**
	 * @return
	 * @throws ExceptionMetier 
	 */
	public ArrayList<ElementListe> creerListeMatiere() throws ExceptionMetier{
		return factory.creerListeMatiere();
	}
	
	public ArrayList<ElementListe> creerListeConge() throws ExceptionMetier{
		return factory.creerListeConge(this.getAnnee());
	}
	public void creerMatiere(UE ue, String nom, String description, int coefficient) {
			matiere = factory.creerMatiere(ue, nom, description, coefficient); 
		}
	/**
	 * @return the formation
	 */
	public Matiere getMatiere() {
		return matiere;
	}
	/**
	 * @return the formation
	 */
	public Formation getFormation() {
		return formation;
	}
	/**
	 * @return the semestre
	 */
	public Semestre getSemestre() {
		return semestre;
	}

	/**
	 * @return
	 * @throws ExceptionMetier 
	 */
	public ArrayList<ElementListe> creerListeAnneeEtude() throws ExceptionMetier{
		return factory.creerListeAnneeEtude();
	}
	
	public void ajouterFormation() throws ExceptionMetier {
		if (formation != null) {
			this.formation.insert();
			
		}
	}

        public ArrayList<ElementListe> creerListeSemestre() throws ExceptionMetier{
            return factory.creerListeSemestre();
        }

		public void setFormationAnnee(Formation formationAnnee) {
			this.formationAnnee = formationAnnee;
		}

		public Formation getFormationAnnee() {
			return formationAnnee;
		}
	public void creerSemestres() throws ExceptionMetier{
		ArrayList<ElementListe> liste = factory.creerListeSemestre(this.getAnnee());
		semestre1=null;
		semestre2=null;
		
		if (liste.size()<3){
			
			if (liste.size()>0){
				semestre1 = factory.creerSemestre();
				semestre1.load(liste.get(0).getId());
				if (liste.size()>1)
				{

					semestre2 = factory.creerSemestre();
					semestre2.load(liste.get(1).getId());
				}
			}
			
		}
	}

	public void creerSemestre1() {
		semestre1=factory.creerSemestre();
	}
	public void creerSemestre2() {
		semestre2=factory.creerSemestre();
	}
	
	public void creerConge (){
		conge=factory.creerConge();
	}

    public void creerSemestre() {
        semestre = factory.creerSemestre();
    }

}
